package com.action.log;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.business.log.LogListBus;
import com.business.log.LogTypeBus;
import com.config.SystemGlobals;

public class UpdateLogType extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
		String action = request.getParameter("action");
		String typeId = request.getParameter("id");
		if ("del".equals(action)) {
			LogListBus llb=new LogListBus();
			if(llb.getAllLogByTypeID(Integer.parseInt(typeId)).size()==0){
			LogTypeBus  ltb = new LogTypeBus();
			ltb.del(typeId);
			out
					.println("<script>alert(\"删除日志分类成功\");window.location=\"user/showlist.jsp\";</script>");
			}else{
				out.println("<script>alert(\"还有日志不能删除这个分类\");window.location=\"user/showlist.jsp\";</script>");
			}
			}
		if ("edit".equals(action)) {
			RequestDispatcher rd = request
					.getRequestDispatcher("user/editlogtype.jsp?no=" + typeId);
			rd.forward(request, response);
		}
	}

}
